﻿Imports System.Windows.Forms
Imports System.IO

Public Class SettingsDialog

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Try
            Main.DeviceID = DeviceIDTextBox.Text.ToString
            Main.ProfileID = ProfileIDTextBox.Text.ToString
            Main.ConsoleID = ConsoleIDTextBox.Text.ToString
            Main.EditProfile = ProfileCheckBox.Checked

            HostName = HostTextBox.Text.ToString
            UserName = UsernameTextBox.Text.ToString
            Password = PasswordTextBox.Text.ToString
            Passive = PassiveCheckBox.Checked

            Dim FileString As String = Application.StartupPath & "\Config.ini"
            'Write Settings to file
            My.Computer.FileSystem.WriteAllText(FileString, "DeviceID = " & Main.DeviceID & vbCrLf & "ProfileID = " & Main.ProfileID & vbCrLf & "ConsoleID = " & Main.ConsoleID & vbCrLf & "Edit Profile = " & Main.EditProfile & vbCrLf & "Host = " & HostName & vbCrLf & "Username = " & UserName & vbCrLf & "Password = " & Password & vbCrLf & "Passive = " & Passive & vbCrLf, False)
        Catch ex As Exception

        End Try

        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub SetIDDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Load ID's into the textboxes
        DeviceIDTextBox.Text = Main.DeviceID
        ProfileIDTextBox.Text = Main.ProfileID
        ConsoleIDTextBox.Text = Main.ConsoleID

        HostTextBox.Text = HostName
        UsernameTextBox.Text = UserName
        PasswordTextBox.Text = Password
        PassiveCheckBox.Checked = Passive

    End Sub

    Private Sub OpenFileButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFileButton.Click
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Main.STFSFilePath = OpenFileDialog1.FileName
            CheckifCON()
            If CheckifCON() = True Then
                ReadIDs()
                DeviceIDTextBox.Text = Main.DeviceID.ToString
                ProfileIDTextBox.Text = Main.ProfileID.ToString
                ConsoleIDTextBox.Text = Main.ConsoleID.ToString
            End If
        End If
    End Sub
End Class
